package top.continew.wechat.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import top.continew.wechat.user.dto.FriendDTO;
import top.continew.wechat.user.entity.FriendRelation;

import java.util.List;

/**
 * 好友关系Mapper接口
 */
@Mapper
public interface FriendRelationMapper extends BaseMapper<FriendRelation> {

    /**
     * 获取用户的所有好友
     *
     * @param userId 用户ID
     * @return 好友列表
     */
    @Select("SELECT " +
            "u.id as userId, u.username, u.nickname, u.avatar, " +
            "fr.remark, fr.group_id as groupId, fg.name as groupName " +
            "FROM friend_relation fr " +
            "JOIN user u ON fr.friend_id = u.id " +
            "LEFT JOIN friend_group fg ON fr.group_id = fg.id " +
            "WHERE fr.user_id = #{userId} " +
            "ORDER BY fg.name, u.nickname")
    List<FriendDTO> findFriendsByUserId(@Param("userId") Long userId);
}
